package bamin.com.bamindaijia.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

import bamin.com.bamindaijia.R;
import bamin.com.bamindaijia.umeng.Defaultcontent;

public class ShareActivity extends ZjbBaseActivity implements View.OnClickListener {

    private ImageView mEnglishLogoIv;
    UMImage image = new UMImage(ShareActivity.this,R.mipmap.daijia);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);
        init();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void setListeners() {
        findViewById(R.id.tv_share).setOnClickListener(this);
        findViewById(R.id.imageView_back).setOnClickListener(this);
    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {

    }

    @Override
    protected void findID() {
        mEnglishLogoIv = (ImageView) findViewById(R.id.iv_english_logo);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_share://友盟分享
                umenShare();
                break;
            case R.id.imageView_back:
                finishTo();
                break;
        }
    }

    private void umenShare() {
        new ShareAction(ShareActivity.this).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
//                        .addButton("umeng_sharebutton_custom", "umeng_sharebutton_custom", "info_icon_1", "info_icon_1")
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
//                                if (snsPlatform.mShowWord.equals("umeng_sharebutton_custom")) {
//                                    Toast.makeText(MainActivity.this, "自定义按钮", Toast.LENGTH_LONG).show();
//                                } else {
                        new ShareAction(ShareActivity.this).withText(Defaultcontent.text + "来自八闽代驾")
                                .withTargetUrl(Defaultcontent.url)
                                .withMedia(image)
                                .setPlatform(share_media)
                                .setCallback(umShareListener)
                                .share();
//                                }
                    }
                }).open();
    }

    /**
     * 分享后的回调
     */
    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Log.d("plat", "platform" + platform);
            if (platform.name().equals("WEIXIN_FAVORITE")) {
                Toast.makeText(ShareActivity.this, platform + " 收藏成功啦", Toast.LENGTH_SHORT).show();

            } else {
                Toast.makeText(ShareActivity.this, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
                Log.e("MainActivity", "分享成功啦: --->>" + platform);

            }
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(ShareActivity.this, platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
            Log.e("MainActivity", "分享失败啦: --->>" + platform);

            if (t != null) {
                Log.d("throw", "throw:" + t.getMessage());
            }
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(ShareActivity.this, platform + " 分享取消了", Toast.LENGTH_SHORT).show();
            Log.e("MainActivity", "分享取消了: --->>" + platform);

        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /** attention to this below ,must add this**/
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
        Log.d("result", "onActivityResult");
    }
}
